// keyValue 互换
function key2Value(originMap) {
  if (!originMap) return
  const result = {}
  Object.keys(originMap).forEach(key => {
    const item = originMap[key]
    result[key] = item.reduce((pre, cur) => {
      const { label, value } = cur
      pre[value] = label
      return pre
    }, {})
  })
  return result
}

// 根据key替换value
function dealResult2Map(resultList, dataMap) {
  resultList.forEach(item => {
    Object.keys(item).forEach(resultKey => {
      //
      const v = item[resultKey]
      if (Object.hasOwnProperty.call(dataMap, resultKey)) {
        const k = `${resultKey}Str`
        item[k] = dataMap[resultKey][v]
      }
    })
  })
}

module.exports = {
  key2Value,
  dealResult2Map
}
